package com.lanju.dao;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.hibernate.SessionFactory;
import org.hibernate.transform.Transformers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.util.StringUtils;

import com.lanju.entity.Bills;
import com.lanju.entity.Community;
import com.lanju.entity.House;
import com.lanju.entity.HouseImg;
import com.lanju.entity.Organization;
import com.lanju.entity.Recom;
import com.lanju.entity.Server;


@Repository
public class RecomDao extends BaseDao<Recom,String>{
    
    private static final Log log = LogFactory.getLog(RecomDao.class);
    @Autowired
   	SessionFactory sessionFactory;
    
    @PersistenceContext(unitName = "financialmarketingUnit")
    private EntityManager entityManager;

    @SuppressWarnings("unchecked")
	public void insertRecommed(Map<String, Object> param) {
    	StringBuffer sql = new StringBuffer("insert into lj_recommend ");
		 if(!StringUtils.isEmpty(param.get("id"))) {
			 sql.append("(recommendId");
		   }
		 if(!StringUtils.isEmpty(param.get("oldUserId"))) {
			 sql.append(",oldUserId");
		   }
		 if(!StringUtils.isEmpty(param.get("phone"))) {
			 sql.append(",phone");
		   }
		 if(!StringUtils.isEmpty(param.get("wxAccount"))) {
			 sql.append(",wxAccount");
		   }
		 if(!StringUtils.isEmpty(param.get("remark"))) {
			 sql.append(",remark");
		   }
		 if(!StringUtils.isEmpty(param.get("type"))) {
			 sql.append(",type");
		   }
		 sql.append(")values(");
		 if(!StringUtils.isEmpty(param.get("id"))) {
			 sql.append("'"+param.get("id")+"'");
		   }
		 if(!StringUtils.isEmpty(param.get("oldUserId"))) {
			 sql.append(",'"+param.get("oldUserId")+"'");
		   }
		 if(!StringUtils.isEmpty(param.get("phone"))) {
			 sql.append(",'"+param.get("phone")+"'");
		   }
		 if(!StringUtils.isEmpty(param.get("wxAccount"))) {
			 sql.append(",'"+param.get("wxAccount")+"'");
		   }
		 if(!StringUtils.isEmpty(param.get("remark"))) {
			 sql.append(",'"+param.get("remark")+"'");
		   }
		 if(!StringUtils.isEmpty(param.get("type"))) {
			 sql.append(",'"+param.get("type")+"'");
		   }
		 sql.append(")");
		 this.getSessionFactory().getCurrentSession().createSQLQuery(sql.toString()).executeUpdate();
	}
    
}
